//	gmBomb.cpp

#include "gmBomb.h"

// Initialise the static data for this type and declare it's gmType name as 'bomb'
GMBIND_INIT_TYPE( gmBomb, "bomb" );

// Implement the function map for this type
GMBIND_FUNCTION_MAP_BEGIN( gmBomb )
    // Declare a gm function called "explode" using gmBomb::gmExplode as it's
    // native callback
    //
	GMBIND_FUNCTION( "explode", gmExplode )
	GMBIND_FUNCTION( "addTime", gmAddTimer)
	//
GMBIND_FUNCTION_MAP_END();


// Implement the property map for this type
GMBIND_PROPERTY_MAP_BEGIN( gmBomb )
    // Declare a property "isExploded" which uses gmBomb::getExploded / gmBomb::setExploded
    // as it's access callbacks. Omitting setExploded will make the property read-only
    //
	GMBIND_PROPERTY( "isExploded", getExploded, setExploded )
	//
GMBIND_PROPERTY_MAP_END();

int gmBomb::gmExplode(gmThread * a_thread)
{
	// Obtain a pointer to the native object associated with the gmBind type
	// instance - you MUST use GetThisObject instead of the usual GameMonkey
	// gmThread::ThisUser functions
	bomb* native = gmBomb::GetThisObject( a_thread );
	// Call the native object's explode method!
	native->explode();
	// return OK, all is well
	return GM_OK; 
}

int gmBomb::gmAddTimer(gmThread * a_thread)
{
	// Obtain a pointer to the native object associated with the gmBind type
	// instance - you MUST use GetThisObject instead of the usual GameMonkey
	// gmThread::ThisUser functions
	GM_CHECK_NUM_PARAMS(2);
	GM_CHECK_INT_PARAM( time, 0 );
	bomb* native = gmBomb::GetThisObject( a_thread );
	// Call the native object's explode method!
	native->addTimer(time);
	// return OK, all is well
	return GM_OK; 
}

bool gmBomb::getExploded( bomb *a_native, gmThread * a_thread, gmVariable * a_operands )
{
    // Set the return of the 'get' method to 0 or 1, depending on whether the
    // bomb's native instance has been blown
    //
    // GM Example:
    //
    // b = bomb();
    // print( b.isExploded );
    //
	a_operands[0].m_value.m_int = (a_native->isExploded ? 1 : 0);
	// Return true, the property get was successful
	return true;
}

bool gmBomb::setExploded( bomb *a_native, gmThread * a_thread, gmVariable * a_operands )
{
    // Set the native bomb's exploded member as 1 or 0, depending on the status
    // of the parameter passed in script
    //
    // GM Example:
    //
    // b = bomb();
    // b.isExploded = 1;
    //
	a_native->isExploded = (a_operands[1].m_value.m_int ? 1 : 0);
	// Return true, the property set was successful
	return true;
}